package com.hanamaki.study.day02;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class FireFoxDriverTestNg03 {

    /* WebDriver 代表 浏览器 对象 */
    WebDriver driver;

    @BeforeClass
    public void setUp() {
        /* 1. 注册驱动的位置  */
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");

        /* 2, 注册驱动 */
        driver = new FirefoxDriver();

    }

    @Test
    public void firefox() {
        /* 打开网址测试  */
        driver.get("https://www.baidu.com");
        /* 如果想要操作 浏览器打开网页的大小问题 可以使用 manage 对象  */

        WebDriver.Options options = driver.manage();
        WebDriver.Window window = options.window();

        /* 在刚刚打开浏览器 网页时 获取网页的初始大小以及初始的坐标位置 */
        /* 首先获取网页的 初始宽高 */
        Dimension size = window.getSize();
        int height = size.getHeight();
        int width = size.getWidth();
        /* 获得网页 打开的坐标起始位置 */
        Point position = window.getPosition();
        int x = position.getX();
        int y = position.getY();

        System.out.println("在对网页进行最大化之前的初始宽高为：" + "(" + width + "," + height + ")" +
                "\n初始坐标为：" + "(" + x + "," + y + ")");

        /* 铺满网页的整个屏幕 */
//        window.fullscreen();

        /* 设置网页的最大化 */
        window.maximize();

        Dimension size1 = window.getSize();
        int height1 = size1.getHeight();
        int width1 = size1.getWidth();
        /* 获得网页 打开的坐标起始位置 */
        Point position1 = window.getPosition();
        int x1 = position1.getX();
        int y1 = position1.getY();

        System.out.println("在对网页进行最大化之后的初始宽高为：" + "(" + width1 + "," + height1 + ")" +
                "\n初始坐标为：" + "(" + x1 + "," + y1 + ")");


        /* 自定义网页的 起始坐标以及 宽高大小 */
        Dimension dimension = new Dimension(500, 500);

        window.setSize(dimension);
        Point point = new Point(0, 0);
        window.setPosition(point);

        Dimension size2 = window.getSize();
        int height2 = size2.getHeight();
        int width2 = size2.getWidth();
        /* 获得网页 打开的坐标起始位置 */
        Point position2 = window.getPosition();
        int x2 = position2.getX();
        int y2 = position2.getY();

        System.out.println("在对网页进行最大化之前的初始宽高为：" + "(" + width2 + "," + height2 + ")" +
                "\n初始坐标为：" + "(" + x2 + "," + y2 + ")");

    }

}
